#include "rgcpp/sys/JobScheduler.h"

class Job1 : public rgcpp::Job
{
	public:
		Job1(int offset) : rgcpp::Job(offset)
		{

		}

	protected:
		void execute()
		{
			for(unsigned int i=0; i<10; i++)
				this->scheduleChildJob(boost::shared_ptr<rgcpp::Job>(new rgcpp::Job()));

			sleep(10);
		}

		void callBack(boost::shared_ptr<Job> child)
		{
			std::cout << "callBack -> " << child->getJobId() << std::endl;

//			if(child->getJobId() == 5)
//			{
//				for(unsigned int i=0; i<5; i++)
//					this->scheduleChildJob(boost::shared_ptr<rgcpp::Job>(new rgcpp::Job(rand() % 20 + 1)));
//			}
		}

		void final()
		{
			std::cout << "Job::final -> " << this->getJobId() << std::endl;
		}
};

int main()
{
	rgcpp::JobScheduler jobScheduler(5);

	jobScheduler.scheduleJob(boost::shared_ptr<rgcpp::Job>(new Job1(2)));

//	jobScheduler.scheduleJob(boost::shared_ptr<rgcpp::Job>(new rgcpp::Job(5)));
//	jobScheduler.scheduleJob(boost::shared_ptr<rgcpp::Job>(new rgcpp::Job(10)));
//	jobScheduler.scheduleJob(boost::shared_ptr<rgcpp::Job>(new rgcpp::Job(15)));
//	jobScheduler.scheduleJob(boost::shared_ptr<rgcpp::Job>(new rgcpp::Job(1)));

	std::string text;
	std::cin >> text;
}
